﻿<UserControl x:Class="Dotway.WPF.Samples.DotwaySampleApplication.TransformInteractionSample"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:controls="clr-namespace:Dotway.WPF.Controls;assembly=Dotway.WPF.Controls">

    <UserControl.Resources>

        <Style x:Key="customInteractionStyle" TargetType="{x:Type controls:TransformInteraction}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type controls:TransformInteraction}">
                        <Grid RenderTransformOrigin="0.5,0.5">
                            <Grid.RenderTransform>
                                <TransformGroup>
                                    <ScaleTransform ScaleX="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Scale}" ScaleY="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Scale}" />
                                    <RotateTransform Angle="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Angle}"/>
                                    <TranslateTransform X="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=X}" Y="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Y}"/>
                                </TransformGroup>
                            </Grid.RenderTransform>

                            <ContentPresenter Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="3" Grid.RowSpan="3"/>

                            <Grid x:Name="PART_ControlContainer" Visibility="Hidden">

                                <Grid x:Name="PART_TranslateControls" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="-5,-5,-5,-5">
                                    <Rectangle Fill="#FFEEEEEE" Stroke="Gray" RadiusX="3" RadiusY="3" Cursor="SizeAll" Height="15" VerticalAlignment="Top" HorizontalAlignment="Stretch" Margin="0,-10,0,0"/>
                                    <Rectangle Fill="#FFEEEEEE" Stroke="Gray" RadiusX="3" RadiusY="3" Cursor="SizeAll" Height="15" VerticalAlignment="Bottom" HorizontalAlignment="Stretch" Margin="0,0,0,-10"/>
                                    <Rectangle Fill="#FFEEEEEE" Stroke="Gray" RadiusX="3" RadiusY="3" Cursor="SizeAll" Width="15" VerticalAlignment="Stretch" HorizontalAlignment="Right" Margin="0,0,-10,0"/>
                                    <Rectangle Fill="#FFEEEEEE" Stroke="Gray" RadiusX="3" RadiusY="3" Cursor="SizeAll" Width="15" VerticalAlignment="Stretch" HorizontalAlignment="Left" Margin="-10,0,0,0"/>
                                </Grid>
                                <Grid x:Name="PART_ClickControls" Width="20" Height="20" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="-10,-10,0,0">
                                    <Rectangle Fill="Red" Stroke="Black" Cursor="Arrow" RadiusX="3" RadiusY="3"/>
                                </Grid>
                                <Grid x:Name="PART_RotateControls"  HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                                    <Rectangle Fill="DimGray" Stroke="Black" RadiusX="3" RadiusY="3" Cursor="Hand" Width="20" Height="20" VerticalAlignment="Top" HorizontalAlignment="Right" Margin="0,-10,-10,0"/>
                                    <Rectangle Fill="DimGray" Stroke="Black" RadiusX="3" RadiusY="3" Cursor="Hand" Width="20" Height="20" VerticalAlignment="Bottom" HorizontalAlignment="Right" Margin="0,0,-10,-10"/>
                                    <Rectangle Fill="DimGray" Stroke="Black" RadiusX="3" RadiusY="3" Cursor="Hand" Width="20" Height="20" VerticalAlignment="Bottom" HorizontalAlignment="Left" Margin="-10,0,0,-10"/>
                                </Grid>
                                <Grid x:Name="PART_ScaleControls"  HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                                    <Rectangle Fill="LightGray" Stroke="DimGray" RadiusX="3" RadiusY="3" Cursor="SizeNESW" Width="20" Height="20" VerticalAlignment="Top" HorizontalAlignment="Right"/>
                                    <Rectangle Fill="LightGray" Stroke="DimGray" RadiusX="3" RadiusY="3" Cursor="SizeNWSE" Width="20" Height="20" VerticalAlignment="Bottom" HorizontalAlignment="Right"/>
                                    <Rectangle Fill="LightGray" Stroke="DimGray" RadiusX="3" RadiusY="3" Cursor="SizeNESW" Width="20" Height="20" VerticalAlignment="Bottom" HorizontalAlignment="Left"/>
                                </Grid>
                            </Grid>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

    </UserControl.Resources>

    <Grid Margin="20">
        <TextBlock x:Name="output" HorizontalAlignment="Center" VerticalAlignment="Top" />

        <controls:TransformInteraction HorizontalAlignment="Left" VerticalAlignment="Center" Click="Control1TransformInteractionClick">
            <Border Background="OliveDrab" Width="150" Height="80" BorderBrush="Black" BorderThickness="1">
                <TextBlock Margin="1" TextWrapping="Wrap" Text="1. Hover over this control to see the interaction controls. Scale, rotate and translate the control." />
            </Border>
        </controls:TransformInteraction>

        <controls:TransformInteraction HorizontalAlignment="Center" VerticalAlignment="Center" Click="Control2TransformInteractionClick">
            <Border Background="RoyalBlue" Width="150" Height="80" BorderBrush="Black" BorderThickness="1">
                <TextBlock Margin="1" TextWrapping="Wrap" Text="2. Hover over this control to see the interaction controls. Scale, rotate and translate the control." />
            </Border>
        </controls:TransformInteraction>

        <controls:TransformInteraction HorizontalAlignment="Right" VerticalAlignment="Center" Click="Control3TransformInteractionClick">
            <Border Background="Olive" Width="150" Height="80" BorderBrush="Black" BorderThickness="1">
                <TextBlock Margin="1" TextWrapping="Wrap" Text="3. Hover over this control to see the interaction controls. Scale, rotate and translate the control." />
            </Border>
        </controls:TransformInteraction>

        <controls:TransformInteraction HorizontalAlignment="Center" VerticalAlignment="Bottom" Click="Control4TransformInteractionClick" Style="{StaticResource customInteractionStyle}">
            <Border Background="DarkGoldenrod" Width="150" Height="80" BorderBrush="Black" BorderThickness="1">
                <RichTextBox Name="richTB" Margin="1">
                    <FlowDocument>
                        <Paragraph>
                            <Run>4. This one uses a custom interaction controls with a subcontrol that can be interacted with.</Run>
                        </Paragraph>
                        <Paragraph>
                            <Run>Another Paragraph</Run>
                        </Paragraph>
                    </FlowDocument>
                </RichTextBox>
            </Border>
        </controls:TransformInteraction>
    </Grid>
</UserControl>
